import basegraphunit from './basegraphunit.js'
import coorPkg from '../coord.js'

class ImageInfo extends basegraphunit.BaseGraphUnit {
    constructor() {
        super();
        this.pos = new coorPkg.RectPos();
        this.x = 0;
        this.y = 0;
        this.angle = 0;

        this.width = 0;
        this.height = 0;
        this.datasize = 0;
        this.scalex = 1;
        this.scaley = 1;
        this.symbolUnitIndex = 0;
        this.fileEx = "jpg";
        this.contentBs64 = "";
        this.imgURL = "";
    }

    translateSubInfo(tx,ty){
        this.x += tx;
        this.y += ty;
    }

    toJson() {
        var jsonobj = {};
        super.toJson(jsonobj);
        jsonobj["x"] = this.x;
        jsonobj["y"] = this.y;
        jsonobj["width"] = this.width;
        jsonobj["height"] = this.height;
        jsonobj["datasize"] = this.datasize;
        jsonobj["scalex"] = this.scalex;
        jsonobj["scaley"] = this.scaley;
        jsonobj["symbolUnitIndex"] = this.symbolUnitIndex;
        jsonobj["fileEx"] = this.fileEx;
        jsonobj["contentBs64"] = this.contentBs64;
        jsonobj["imgURL"] = this.imgURL;
        return jsonobj;
    }
    fromJson(obj) {
        super.fromJson(obj);
        this.x = obj["x"];
        this.y = obj["y"];
        
        this.width = obj["width"];
        this.height = obj["height"];

        this.pos.left = this.x;
        this.pos.top = this.y;
        this.pos.width = this.width;
        this.pos.height = this.height;

        this.datasize = obj["datasize"];
        this.scalex = obj["scalex"];
        this.scaley = obj["scaley"];
        this.symbolUnitIndex = obj["symbolUnitIndex"];
        this.fileEx = obj["fileEx"];
        this.contentBs64 = obj["contentBs64"];
        this.imgURL = obj["imgURL"];
    }

    cloneCopy() {
        var pNewInfo = new ImageInfo();
        super.cloneCopy(pNewInfo);
        pNewInfo.x = this.x;
        pNewInfo.y = this.y;
        pNewInfo.width = this.width;
        pNewInfo.height = this.height;
        pNewInfo.datasize = this.datasize;
        pNewInfo.scalex = this.scalex;
        pNewInfo.scaley = this.scaley;
        pNewInfo.symbolUnitIndex = this.symbolUnitIndex;
        pNewInfo.fileEx = this.fileEx;
        pNewInfo.contentBs64 = this.contentBs64;
        pNewInfo.imgURL = this.imgURL;
        return pNewInfo;
    }
}

export default { ImageInfo }

